<?php
	/**
	 * 游戏里加好友
	 */
    class AddFriend extends APIBase {
		
		public $tag = "AddFriend";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			$this->initDataRedis(0);
			$this->inithttp();
			return true;
		}
		public function logic() {
			$uid = $this->uid;
			$otherUid = $this->param['uid'];
			if($otherUid==''){
				$this->returnError(301,'参数错误!');
			}
			$self_passport = $this->data_redis->hget('hu:'.$uid,'passport');
			$other_passport = $this->data_redis->hget('hu:'.$otherUid,'passport');
			if($self_passport=='' || $other_passport==''){
				$this->returnError(302,'参数错误!');
			}
            $url = Config::$add_friend_url;
			$data = array('inviter_passport'=>$self_passport,'invitee_passport'=>$other_passport,'type'=>2);
			$result = $this->http->AsyncPost($url,$data);
			$this->e($result);
			$resultArr = json_decode($result,true);
			if($resultArr['ret']){
				if($resultArr['info']){
					//$this->e($resultArr['info']['desc'].'-303');
					$this->returnError(303,$resultArr['info']);
				}else{
					$this->returnError(0,'消息已发出,请稍等');
				} 
			}else{
				//$this->e($resultArr['info']['desc'].'---302');
				$this->returnError(302,$resultArr['info']['desc']);
			}
			
		}
		
        public function after() {
			$this->deinitCacheRedis();
			$this->deinithttp();
			$this->deinitDataRedis();
		}
    }
?>
